2020-2021 Sunseeker Telemetry and Lighting System
sd24_b_ex1_singleConvSingleChannel.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //*****************************************************************************
35 // MSP430F673x Demo - SD24_B, Single Conversion on Single Channel Polling IFG
36 //
37 // Description: This program uses the SD24_B module to perform a single
38 // conversion on a single channel. The SD24_B interrupt flag for channel 2 is
39 // polled to determine when a conversion has completed. Test by applying a
40 // voltage to channel 2 (SD2P0, SD2N0) and setting a breakpoint at the line
41 // indicated below. Run program until it reaches the breakpoint, then use the
42 // debugger's watch window to view the conversion results. Results (upper 16
43 // bits only) for channel 2 are stored in variable "results".
44 // ACLK = n/a, MCLK = SMCLK = DCO = ~ 1.1MHz
45 // //* For minimum Vcc required for SD24_B module - see datasheet *//
46 // //* 100nF cap between Vref and AVss is recommended when using 1.5V REF *//
47 //
48 // MSP430F673x
49 // -----------------
50 // /|\| XIN|-
51 // | | |
52 // --|RST XOUT|-
53 // | |
54 // Vin+ -->|SD2P0 |
55 // Vin- -->|SD2N0 |
56 // | |
57 // | VREF |---+
58 // | | |
59 // | | -+- 100nF
60 // | | -+-
61 // | | |
62 // | AVss |---+
63 // | |
64 //
65 // M. Swanson
66 // Texas Instruments, Inc
67 // December 2011
68 // Built with CCS Version: 5.1.0 and IAR Embedded Workbench Version: 5.40.1
69 //*****************************************************************************
70 
71 /* uint32_t to store SD24_B conversion result */
72 uint32_t results;
73 
74 void main(void)
75 {
76  WDT_A_hold(WDT_A_BASE); // Stop WDT
77 
78  // Select internal REF
79  // Select SMCLK as SD24_B clock source
80  SD24_B_initParam initParam = {0};
81  initParam.clockSourceSelect = SD24_B_CLOCKSOURCE_SMCLK;
82  initParam.clockPreDivider = SD24_B_PRECLOCKDIVIDER_1;
83  initParam.clockDivider = SD24_B_CLOCKDIVIDER_1;
84  initParam.referenceSelect = SD24_B_REF_INTERNAL;
85  SD24_B_init(SD24_BASE, &initParam);
86 
87  SD24_B_initConverterParam initConverterParam = {0};
88  initConverterParam.converter = SD24_B_CONVERTER_2;
89  initConverterParam.alignment = SD24_B_ALIGN_RIGHT;
90  initConverterParam.startSelect = SD24_B_CONVERSION_SELECT_SD24SC;
91  initConverterParam.conversionMode = SD24_B_SINGLE_MODE;
92  SD24_B_initConverter(SD24_BASE, &initConverterParam);
93 
94  __delay_cycles(0x3600); // Delay for 1.5V REF startup
95 
96  while (1)
97  {
98  SD24_B_startConverterConversion(SD24_BASE,
99  SD24_B_CONVERTER_2); // Set bit to start conversion
100 
101  // Poll interrupt flag for channel 2
102  while( SD24_B_getInterruptStatus(SD24_BASE,
103  SD24_B_CONVERTER_2,
104  SD24_B_CONVERTER_INTERRUPT) == 0 );
105 
106  results = SD24_B_getResults(SD24_BASE,
107  SD24_B_CONVERTER_2); // Save CH2 results (clears IFG)
108 
109  __no_operation(); // SET BREAKPOINT HERE
110  }
111 }
112 
__no_operation()
__delay_cycles(500000)